<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import= "com.roadmap.common.BaseConst"%>
<%@ page import= "com.roadmap.struts.action.ActionConst"%>
<%@ page import= "com.roadmap.common.RdcResourceBundle"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String user_ssn_id = (String)request.getSession().getAttribute(ActionConst.Aspirant_Id_In_Session);
String user_req_id = (String)request.getParameter(ActionConst.Aspirant_Id_In_Request);
if(user_req_id == null){
	user_req_id = user_ssn_id;
}
String score_req_id = (String)request.getParameter("id");
if(score_req_id == null){
	score_req_id = "";
}
Object host = request.getAttribute(ActionConst.Visitor_Is_Owner);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/> 
<link href="res/css/layout.css" rel="stylesheet" type="text/css" media="all" />
<link href="res/css/home.css" rel="stylesheet" type="text/css" media="all" />
<link href="res/css/widget.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="res/js/func.js"></script>
<script type="text/javascript" src="res/js/util.js"></script>
<script type="text/javascript" src="res/js/home.js"></script>
<script type="text/javascript" src="dwr/engine.js"> </script>
<script type="text/javascript" src="dwr/util.js"> </script>
<script type="text/javascript" src="res/js/widget.js"></script>
<script type='text/javascript' src="dwr/interface/RdcAjax.js"> </script>
<script type='text/javascript' src="dwr/interface/ScoreHandler.js"> </script>
<script type='text/javascript' src="dwr/interface/ProfileHandler.js"> </script>
<title><bean:write name="<%=ActionConst.Aspirant_Name_In_Request %>"/>的主页 | <%=RdcResourceBundle.COMPANY_NAME %></title>

</head>

<body onload="init();">
	<jsp:include page="/admin/myheader.jsp"></jsp:include>
	
	<!-- main body -->
	<div class="mainbody">
	<div class="myhome">	
		<div class="left-part">
			<div class="slidebar">
				<ul>
					<li><img src="<%=BaseConst.PURIKURA_DIR_BIG + user_req_id %>.gif?temp=<%=System.currentTimeMillis() %>" alt="<%=RdcResourceBundle.COMPANY_NAME %>"/></li>
					<logic:present name="<%=ActionConst.Visitor_Is_Owner %>"><li><a href="purikura.do">修改头像</a></li></logic:present>
				</ul>
			</div>
			 
			<jsp:include page="/pagelet/lifeLinksPagelet.jsp"/>
			<jsp:include page="/pagelet/msgLinksPagelet.jsp"/>
			
			<div class="slidebar">
				<ul>
					<li class="title">好友<span class="float-right"><a href="friend.do?act=view&uid=<%=user_req_id %>">全部</a></span></li>
					<logic:notPresent name="friends">
					<li>没有好友</li>
					<li><%if(host != null){%>您可以通过<a href='searchFriends.do?act=view'>这里</a>搜索并添加好友<%} %></li>
					</logic:notPresent>
					
					<logic:present name="friends">
					<logic:iterate id="friend" name="friends">
					<bean:define id='friendId' name='friend' property='friendId'/>
					<li><a href="aspirant.do?uid=<%=friendId %>"><bean:write name='friend' property='name'/></a><em>频率(<bean:write name='friend' property='frequency'/>)</em></li>
					</logic:iterate>
					</logic:present>
				</ul>
			</div>
		</div>
		
		<div class="middle-part">
			<div class="homeName">
				<ul>
					<li><h2><bean:write name="<%=ActionConst.Aspirant_Name_In_Request %>"/></h2></li>
				</ul>
			</div>
			
			<div class="navg">
				<ul id="aspirant_ul">
					<li><a id="state" href="aspirant.do?uid=<%=user_req_id %>#v=state" onfocus="this.blur();" onclick="showAspDiv(this.id);">最新状态</a></li>
					<li><a id="infor" href="aspirant.do?uid=<%=user_req_id %>#v=infor" onfocus="this.blur();" onclick="showAspDiv(this.id);">个人资料</a></li>
					<li><a id="score" href="aspirant.do?uid=<%=user_req_id %>#v=score" onfocus="this.blur();" onclick="showAspDiv(this.id);">个人成绩</a></li>
				</ul>
			</div>
						
			<!-- latest status -->
			<div id="stateDiv" class="section"></div>
			
			<!-- latest activities -->
			<div id="behavDiv" class="section"></div>
			
			<!-- profile information -->
			<div id="inforDiv" class="section"></div>
			
			<!-- personal achievements -->
			<div id="scoreDiv" class="section"></div>
			
		</div><!-- middle-part -->
		
		<div class="right-part"></div>
		
	</div><!-- myhome -->	
	<div class="clear-div"></div>
	</div><!-- mainbody -->
	
	<jsp:include page="/res/jsp/footer.jsp"></jsp:include>

<script type="text/javascript">
	var loading = "loading..."; // initialize each division
	var _XMLHttpRequestObject = getXHR();
	var _acts = ["<%=ActionConst.Anchor_Parameter_State%>",	"<%=ActionConst.Anchor_Parameter_Profile%>", "<%=ActionConst.Anchor_Parameter_Score%>" ];
	
	var datePicker = new DatePicker();
	
	function getXHR(){
		var xhr = false;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} 
		else if (window.ActiveXObject) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");			
		}
		
		return xhr;
	}
		
	function init(){	
		setUID("<%=user_req_id%>");
		setScoreId("<%=score_req_id%>");
		
		var urlParam = getParam();		
		for (var i = 0; i < _acts.length; i++){
			$(_acts[i] + "Div").innerHTML = loading;
			if (urlParam == _acts[i]){	
				showAspDiv(urlParam);
			}
		}	
	}
	
	function getParam(){
		var thisURL = document.location.href;
		var splitURL = thisURL.split("<%=ActionConst.Anchor_Parameter_Flag%>");
		var urlParam = splitURL[splitURL.length - 1];
		var valid = false;
		for (var i = 0; i < _acts.length; i++){
			if (urlParam == _acts[i]){
				valid = true;
				break;
			}
		}		
		if(valid == false)
			urlParam = "state";		
		return urlParam;
	}
	
	var portableTask = null;
	var portableGoal = null;
	function getDivContent(xhr, param){
		var requrl = param + ".do?<%=ActionConst.Aspirant_Id_In_Request%>=<%=user_req_id%>";			
		var divID = param + "Div";		
		if(xhr) {
			var obj = document.getElementById(divID);			
			xhr.open("POST", requrl);
			xhr.setRequestHeader("If-Modified-Since", "Sat,1 Jan 2009 00:00:00 GMT");
			xhr.send(null);
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					obj.innerHTML = xhr.responseText;
					initAspDiv(param);
					
					// when the 'state' page is loaded, create a portable information panel if necessary
					if(param === "state") {
						if(portableTask === null && RDC.gui.exist("executableTasks")){
							portableTask = new PortablePanel($("executableTasks"));
							node = RDC.gui.cloneNode("taskDetails", {idSuffix:"_cloned"});
							portableTask.addContent(node);
						}
						
						if(portableGoal === null && RDC.gui.exist("executableGoals")){
							portableGoal = new PortablePanel($("executableGoals"));
							node = RDC.gui.cloneNode("goalDetails", {idSuffix:"_cloned"});
							portableGoal.addContent(node);
						}
					}
				}
			}
		}
	}

	function showAspDiv(param){
		var urlParam = getParam();
		var kids = $("aspirant_ul").getElementsByTagName("LI");		
		for (var i = 0; i < kids.length; i++){
			var nd = kids[i];
			var eld = nd.firstChild.id;
			if(eld == param){
				nd.id = "selected";
				displayCompt(eld + "Div");
				var val = $(eld + "Div").innerHTML;
				if(urlParam == param || val == loading){
					RDC.gui.showProgressIn($(eld + "Div"));
					getDivContent(_XMLHttpRequestObject, param);
				}				
			}
			else {
				nd.id = "unselected";
				RDC.gui.hide(eld + "Div");
			}			
		}		
	}	
	
	
</script>
</body>

</html>
